<?php
$s=($_REQUEST['s']!="")?$_REQUEST['s']:"C:/Users/Administrator/Pictures/5eaf050830f31.png";
$cookie=($cookie!="")?$cookie:"SPC_F=jiwbmcvHbMArpnpfTDAECyakSImvjawj; SPC_CDS_CHAT=7b20404a-8bad-489c-9a1e-459e6d1b61c0; UYOMAPJWEMDGJ=; SC_DFP=RHSMuqKccbTWcPspmXSaPHuKLLcMEAwq; trackerV3ClientId_v2=2762719306; _ga=GA1.2.617917402.1729737269; _ga_LNRE6RR9PR=GS1.1.1729737268.1.1.1729737559.60.0.0; SPC_CNSC_SESSION=69396530891fa633511223598ec5f8f6_2_1904060; SPC_SC_OFFLINE_TOKEN=eyJkYXRhIjoiQTVaUkpINFRCWUZwQTNpVk53eDU5azU2S3VFMkFWc1o3c29KSEZSRjlqVFduS2JuaEo5aXNLQTI1Zkh4cWc1ZU84NTFlQXlHL1VxWW0rL2VwMk1yalBtTlQwOHF6T0RsU040dFNBSXNjUTFvaW1GYmlYOUpveFRLNTFJQkpVUGF2WEtpU2NsVURiOHcwWmExNTNmeFlRPT0iLCJpdiI6IkxRQTkxd3ZITUU4M0ZNVkhVeHpGclE9PSIsInNpZ24iOiI0N1RCYXFtcVdOVWRMSVhxMEJIMUl3VTJFMG42dDk0RCsvclB1ZVNrd2FKNWNpdmtEdVhKaEc3UEkrM2ZsRmEvS0VmQ0YrbVNrMXkyZkJmOWJxaU9CQT09In0=; SPC_CNSC_TK=7d0f92f1f44be11103f4c63ed9ce5652; SPC_CNSC_UD=1_1904060; CNSC_SSO=NjlHRjk3a3ZmOVd3MmYzNlAnFZ8lFeXBQ027d1gMRP/OikogGNuKrVxtI36ugWqZ";
$postdata=<<<TEXTPOST
{"_header":{"version":1,"sign":"SFtTHV-79131bf54c093fc001fb187fbd3c09fd-1730435323","biz":4207,"app_version":"mms-3.0.0","sdk_version":"mms-3.0.0","os_type":2,"request_id":"a369e3bbab784a1a9e2d7ae2753e7959","device_model":"Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/127.0.0.0 Safari/537.36","client_region":"CN"},"count":1}
TEXTPOST;
$count=strlen($postdata);
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, "https://api.mms.shopee.cn/uploadapi/api/v1/image/preupload");

curl_setopt($ch, CURLOPT_USERAGENT, "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/127.0.0.0 Safari/537.36");
curl_setopt($ch, CURLOPT_REFERER, "https://seller.shopee.cn/");
curl_setopt($ch, CURLOPT_COOKIE,$cookie);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, "false");
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, "2");
curl_setopt($ch, CURLOPT_RETURNTRANSFER,1);
curl_setopt($ch, CURLOPT_FOLLOWLOCATION,0);
curl_setopt($ch, CURLOPT_VERBOSE,0);
curl_setopt($ch, CURLOPT_HTTPHEADER, array(
    "Host:api.mms.shopee.cn",
    "Connection:keep-alive",
    "Content-Length: {$count}",
    "Accept:application/json, text/plain, */*",
    "Origin:https://seller.shopee.cn",
    "User-Agent:Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/127.0.0.0 Safari/537.36",
    "Content-Type:application/json;charset=UTF-8",
    "Accept-Language:zh-CN,zh;q=0.9,en-US;q=0.8,en;q=0.7,ja;q=0.6,bg;q=0.5,zh-TW;q=0.4,ru;q=0.3,th;q=0.2",
    "Pragma:no-cache",
    "Cache-Control:no-cache",
    "sec-ch-ua:\"Not)A;Brand\";v=\"99\", \"Google Chrome\";v=\"127\", \"Chromium\";v=\"127\"",
    "sec-ch-ua-platform:\"Windows\"",
    "sec-ch-ua-mobile:?0",
    "Sec-Fetch-Site:same-site",
    "Sec-Fetch-Mode:cors",
    "Sec-Fetch-Dest:empty"
));
curl_setopt($ch, CURLOPT_HEADER, 0);
curl_setopt($ch, CURLOPT_TIMEOUT, 60);
curl_setopt($ch, CURLOPT_POST, true );
curl_setopt($ch, CURLOPT_POSTFIELDS, $postdata);
$result=curl_exec($ch);
curl_close($ch);
//echo $result;
$data=json_decode($result,1);
//print_r($data);
if($_REQUEST['s']){
    echo $data['data']['model']['short_product_name']['value'];
}else{
    $img_id=$data['data']['fingerprint_infos'][0]['img_id'];
}

//echo $img_id;
//https://collect.yangjc.com/httpapi/index.php?action=weixin_sort_title&s=&XDEBUG_SESSION_START=5432

// 接收上传图片的服务器端URL
$uploadUrl = 'https://up-ws.img.shopee.cn/file/upload';

// 初始化cURL会话
$ch = curl_init();

// 设置要上传的文件
$cfile = new CURLFile($s);
//print_r($cfile);exit;
// 设置POST数据
$data = array(
    'file' => $cfile,
    'key' => $img_id,
    'token' => 'd6e4b41e5f512916477077ff856e09f01df7bef5:MTllZmYyYzliZTI0Yzk5YjFkODczMzZkYWYxODU0MTBkOTU4ZmIwMA==:eyJjYWxsYmFja1VybCI6Imh0dHBzOi8vYXBpLm1tcy5zaG9wZWUuY24vdXBsb2FkYXBpL2FwaS92MS9jYWxsYmFjay93c2V2ZW50IiwiY2FsbGJhY2tCb2R5IjoiYnVja2V0PSQoYnVja2V0KVx1MDAyNmtleT0kKGtleSlcdTAwMjZmaWxlX3NpemU9JChmc2l6ZSlcdTAwMjZpcD0kKGlwKVx1MDAyNm1pbWVfdHlwZT0kKG1pbWVUeXBlKVx1MDAyNmNvc3Q9JChjb3N0VGltZSlcdTAwMjZlbnY9bGl2ZVx1MDAyNmNpZD1jblx1MDAyNmJpej00MjA3Iiwic2NvcGUiOiJnYXJlbmEtaW1hZ2UiLCJkZWFkbGluZSI6IjE3MzA1MDgyMjIwMDAiLCJvdmVyd3JpdGUiOjAsImZzaXplTGltaXQiOjB9',
    'mimeType' => 'image/jpeg',
);

// 设置请求头
$headers = array(
    'Content-Type: multipart/form-data',
);
curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);

// 设置cookie信息，假设cookie是一个字符串，格式如 "name1=value1; name2=value2"
curl_setopt($ch, CURLOPT_COOKIE, $cookie);
curl_setopt($ch, CURLOPT_COOKIE,$cookie);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, "false");
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, "2");

// 设置cURL选项
curl_setopt($ch, CURLOPT_URL, $uploadUrl);
curl_setopt($ch, CURLOPT_POST, true);
curl_setopt($ch, CURLOPT_POSTFIELDS, $data);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);

// 执行cURL请求
$response = curl_exec($ch);

// 检查是否有错误
if (curl_error($ch)) {
    echo 'Curl error: '. curl_error($ch);
} else {
    return "https://s-cf-sg.shopeesz.com/file/{$img_id}_tn";
}

curl_close($ch);